<template>
  <div class="rockmans-similar">
    <div class="tips" v-if="manList.length>0">英雄所见略同，TA们也有相似板块的持仓股</div>
    <div class="tips" v-else>哎哟...目前没有与TA相似的牛人哦~</div>

    <div class="list">
      <a href="javascript:;" v-for="(item, index) in manList" >
        <img :src="item.userHead" :data-clientId="item.clientId" @click.stop.prevent="toOtherDetail">
      </a>
    </div>
  </div>
</template>

<script>
  import RemoteDAO from 'common/remoteDAO'
  import CommonUtil from 'common/common.util'
  import LocalDAO from 'common/localDAO'

  export default {
    data () {
      return {
        manList:[],
        test:'test'
      }
    },
    props:{
      clientId:{
        type:String
      }
    },
    created:function(){
      this.fetchData()
    },
    watch: {
      '$route.query.userCode' (to, from) {
        //跳转相同页面，组件不重新构建，无法调用created,故需监听
        this.fetchData ()
      }
    },
    methods:{
      fetchData(){
        var self = this;
        var args= {};
        args.client_id = self.clientId;
        RemoteDAO.callJCL30024(args, function(response) {
          if (Number(response.error) === 0) {
            var userCodes = [];
            _.each(response.data.body.data, function(item, index) {
              var userCode = item.client_id;
              userCodes.push(userCode);
            });

            RemoteDAO.callUC12008316(self.clientId, userCodes.join(","), function(response) {
              var list = [];
              if (Number(response.error) === 0) {
                _.each(response.data.body, function(item, index) {
                  var object = {};
                  object.clientId = item.USER_CODE;
                  object.userHead = item.USER_HEAD == "" ? CommonUtil.getDefaultUserHead(item.USER_CODE) : item.USER_HEAD;
                  list.push(object);
                });
                self.manList = list
              }
            });
          }
        });
      },
      toOtherDetail(e){
        var self  = this;
        var target = e.currentTarget;
        var clientId = target.getAttribute('data-clientId');
        self.$router.push({path: '/otherdetail', query: {userCode: clientId}});
      }
    }
  }
</script>

<style scoped>

</style>
